package com.steve.summary.three_PC;

import java.util.Arrays;
import java.util.List;

/**
 * @Author: STEVE
 * @Description: 主程序
 * @since: 2025-05-22
 */
public class Main {

    public static void main(String[] args) {
        List<Participant> participants = Arrays.asList(
                new Participant("DB1"),
                new Participant("DB2"),
                new Participant("DB3")
        );

        /**
         * 强制让第二个参与者在preCommit阶段失败
         * participants.get(1).setForceFail(true);
         */

        Coordinator coordinator = new Coordinator(participants);
        boolean success = coordinator.execute3PC("TX-123", 3000);
        System.out.println("事务结果：" + (success ? "成功" : "失败"));
    }

}
